/**
 * Created by huzhihui on 2016/9/30.
 */

/**
 * 全局列表json
 * @type {{}}
 */
var TAB_JSON = {
    list: [
        {
            listName: '首页',/*tab名称*/
            listUrl: 'html/main.html',/*页面路径*/
            listUuid: 'uuid-main',/*tab唯一标识*/
            listIcon: '',/*左侧显示图标*/
            listRightIcon: '',/*右侧显示图标*/
            listNumber: '',/*右侧显示数字数据*/
            listNumberColor: '',/*右侧显示数字数据样式*/
            isHtml: true/*是否是页面，false为折叠tab*/,
            tempId : 1
        },
        {
            listName: '商品',
            listUrl: '',
            listUuid: 'uuid-product',
            listIcon: 'am-icon-th-list',/*左侧显示图标*/
            listRightIcon: 'am-icon-angle-right',
            listNumber: '',
            listNumberColor: '',
            isHtml: false,
            subList: [
                {
                    listName: '商品管理',
                    listUrl: 'html/system-product.html',
                    listUuid: 'uuid-system-product',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                },
                {
                    listName: '商品分类管理',
                    listUrl: 'html/system-product-category.html',
                    listUuid: 'uuid-system-category',
                    listIcon: 'am-icon-product-hunt',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                }
            ]
        },
        {
            listName: '圈子',/*tab名称*/
            listUrl: 'html/order-create.html',/*页面路径*/
            listUuid: 'uuid-order-create',/*tab唯一标识*/
            listIcon: 'am-icon-th-list',/*左侧显示图标*/
            listRightIcon: 'am-icon-angle-right',/*右侧显示图标*/
            listNumber: '',/*右侧显示数字数据*/
            listNumberColor: 'am-badge am-badge-secondary',/*右侧显示数字数据样式*/
            isHtml: false/*是否是页面，false为折叠tab*/,
            subList: [
                {
                    listName: '圈子绘制',
                    listUrl: 'html/system-shop.html',
                    listUuid: 'uuid-system-shop',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                }
            ]
        },
        {
            listName: '订单',/*tab名称*/
            listUrl: 'html/order-list.html',/*页面路径*/
            listUuid: 'uuid-order-list',/*tab唯一标识*/
            listIcon: 'am-icon-th-list',/*左侧显示图标*/
            listRightIcon: 'am-icon-angle-right',/*右侧显示图标*/
            listNumber: '',/*右侧显示数字数据*/
            listNumberColor: 'am-badge am-badge-secondary',/*右侧显示数字数据样式*/
            isHtml: false/*是否是页面，false为折叠tab*/,
            subList: [
                {
                    listName: '订单列表',
                    listUrl: 'html/system-order.html',
                    listUuid: 'uuid-system-order',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                }
            ]
        },
        {
            listName: '会员',/*tab名称*/
            listUrl: 'html/order-list.html',/*页面路径*/
            listUuid: 'uuid-order-list',/*tab唯一标识*/
            listIcon: 'am-icon-th-list',/*左侧显示图标*/
            listRightIcon: 'am-icon-angle-right',/*右侧显示图标*/
            listNumber: '',/*右侧显示数字数据*/
            listNumberColor: 'am-badge am-badge-secondary',/*右侧显示数字数据样式*/
            isHtml: false/*是否是页面，false为折叠tab*/,
            subList: [
                {
                    listName: '会员管理',
                    listUrl: 'html/system-member.html',
                    listUuid: 'uuid-system-member',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                },
                {
                    listName: '会员等级管理',
                    listUrl: 'html/system-member-bank.html',
                    listUuid: 'uuid-system-rank',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                },
                {
                    listName: '评论管理',
                    listUrl: 'html/system-comment.html',
                    listUuid: 'uuid-system-postreview',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                }
            ]
        },
        {
            listName: '营销',/*tab名称*/
            listUrl: 'html/order-list.html',/*页面路径*/
            listUuid: 'uuid-order-list',/*tab唯一标识*/
            listIcon: 'am-icon-th-list',/*左侧显示图标*/
            listRightIcon: 'am-icon-angle-right',/*右侧显示图标*/
            listNumber: '',/*右侧显示数字数据*/
            listNumberColor: 'am-badge am-badge-secondary',/*右侧显示数字数据样式*/
            isHtml: false/*是否是页面，false为折叠tab*/,
            subList: [
                {
                    listName: '优惠券管理',
                    listUrl: 'html/system-coupon.html',
                    listUuid: 'uuid-system-coupon',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                },
                {
                    listName: 'banner管理',
                    listUrl: 'html/system-banner.html',
                    listUuid: 'uuid-system-banner',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                }
            ]
        },
        {
            listName: '系统',/*tab名称*/
            listUrl: 'html/order-list.html',/*页面路径*/
            listUuid: 'uuid-order-list',/*tab唯一标识*/
            listIcon: 'am-icon-th-list',/*左侧显示图标*/
            listRightIcon: 'am-icon-angle-right',/*右侧显示图标*/
            listNumber: '',/*右侧显示数字数据*/
            listNumberColor: 'am-badge am-badge-secondary',/*右侧显示数字数据样式*/
            isHtml: false/*是否是页面，false为折叠tab*/,
            subList: [
                {
                    listName: '管理员',
                    listUrl: 'html/system-admin.html',
                    listUuid: 'uuid-system-admin',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                },
                {
                    listName: '角色管理',
                    listUrl: 'html/system-role.html',
                    listUuid: 'uuid-system-role',
                    listIcon: 'am-icon-truck',
                    listRightIcon: '',
                    listNumber: '',
                    listNumberColor: 'admin-icon-yellow',
                    isHtml: true
                }
            ]
        }
    ]
};

/**
 * 重定位到登录页面
 * @returns
 */
function $configToLogin () {
	window.location = $html.index;
};

/**
 * 添加 iframe tab方法
 * @param iframeUrl
 * @param tabName
 * @param iframeUuid
 * @returns
 */
function $addIframeTal(iframeUrl, tabName, iframeUuid) {
	var tabCounter = 0;
    var $tab = $('#admin-tab-body-index');
    var $nav = $tab.find('.am-tabs-nav');
    var $bd = $tab.find('.am-tabs-bd');
	var haveFlg = false;
	//判断是否打开了该标签页，不能重复打开标签页
	$('#admin-tab-body-index>ul>li').each(function(index) {
		if ($(this).attr('iframe-uuid') == iframeUuid) {
			$tab.tabs('open', index);
			haveFlg = true;
			return;
		}
	});
	if (haveFlg == true) {
		return;
	}

	//不存在该tab则新建tab
	var nav = '<li iframe-uuid="' + iframeUuid + '">'
			+ '<span class="am-tab-refresh am-icon-refresh" iframe-url="'
			+ iframeUrl + '" iframe-uuid="' + iframeUuid + '"></span>'
			+ '<span class="am-icon-close"></span>'
			+ '<a href="javascript: void(0)" iframe-uuid="' + iframeUuid + '">'
			+ tabName + '</a></li>';
	var content = '<div class="am-tab-panel" style="height: 100%"><iframe  id="'+iframeUuid+'" src="'
			+ iframeUrl
			+ '" class="admin-iframe-html" style="width: 100%;height: 100%;"></iframe></div>';
	$nav.append(nav);
	$bd.append(content);
	$tab.tabs('refresh');
	layerLoad = layer.load();
	//$('#admin-tab-body-index').tabs('open',$('#admin-tab-body-index>ul>li').length -1);
	setTimeout(
			"$('#admin-tab-body-index').tabs('open',$('#admin-tab-body-index>ul>li').length -1);",
			50);
	$('#'+iframeUuid).load(function(){
    	layer.close(layerLoad);
    });
};


